package com.ruoyi.qms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.qms.domain.MesNonconformity;
import com.ruoyi.qms.service.IMesNonconformityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 不合格品Controller
 * 
 * @author ruoyi
 * @date 2021-11-10
 */
@RestController
@RequestMapping("/nonconformity")
public class MesNonconformityController extends BaseController
{
    @Autowired
    private IMesNonconformityService mesNonconformityService;

    /**
     * 查询不合格品列表
     */
    @PreAuthorize(hasPermi = "qms:nonconformity:list")
    @GetMapping("/list")
    public TableDataInfo list(MesNonconformity mesNonconformity)
    {
        startPage();
        List<MesNonconformity> list = mesNonconformityService.selectMesNonconformityList(mesNonconformity);
        return getDataTable(list);
    }

    /**
     * 导出不合格品列表
     */
    @PreAuthorize(hasPermi = "qms:nonconformity:export")
    @Log(title = "不合格品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesNonconformity mesNonconformity) throws IOException
    {
        List<MesNonconformity> list = mesNonconformityService.selectMesNonconformityList(mesNonconformity);
        ExcelUtil<MesNonconformity> util = new ExcelUtil<MesNonconformity>(MesNonconformity.class);
        util.exportExcel(response, list, "不合格品数据");
    }

    /**
     * 获取不合格品详细信息
     */
    @PreAuthorize(hasPermi = "qms:nonconformity:query")
    @GetMapping(value = "/{noncUuid}")
    public AjaxResult getInfo(@PathVariable("noncUuid") String noncUuid)
    {
        return AjaxResult.success(mesNonconformityService.selectMesNonconformityByNoncUuid(noncUuid));
    }

    /**
     * 新增不合格品
     */
    @PreAuthorize(hasPermi = "qms:nonconformity:add")
    @Log(title = "不合格品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesNonconformity mesNonconformity)
    {
        return toAjax(mesNonconformityService.insertMesNonconformity(mesNonconformity));
    }

    /**
     * 修改不合格品
     */
    @PreAuthorize(hasPermi = "qms:nonconformity:edit")
    @Log(title = "不合格品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesNonconformity mesNonconformity)
    {
        return toAjax(mesNonconformityService.updateMesNonconformity(mesNonconformity));
    }

    /**
     * 删除不合格品
     */
    @PreAuthorize(hasPermi = "qms:nonconformity:remove")
    @Log(title = "不合格品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noncUuids}")
    public AjaxResult remove(@PathVariable String[] noncUuids)
    {
        return toAjax(mesNonconformityService.deleteMesNonconformityByNoncUuids(noncUuids));
    }
}
